﻿<UserControl x:Class="Mengsk.ProxyDelivery.Print.UI.PrintUserControl" 
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Mengsk.ProxyDelivery.Print.UI" xmlns:Print="clr-namespace:Mengsk.ProxyDelivery.Print" 
             mc:Ignorable="d" 
               xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
             d:DesignHeight="300" d:DesignWidth="900" Loaded="UserControl_Loaded" Name="ucPrint">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid Grid.Row="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="卖家编号:" Margin="3" VerticalAlignment="Center"/>
                <TextBox Name="tbSellerId" Margin="3" Width="80" VerticalAlignment="Center"/>
                <TextBlock Text="结束时间:" Margin="3" VerticalAlignment="Center"/>
                <xctk:DateTimePicker Name="dpEnd" Margin="3" VerticalAlignment="Center" Width="160"  Format="Custom" FormatString="yyyy-MM-dd HH:mm:ss"/>
                <Button x:Name="btnDownloadOrder" Content="下载未打印订单" Click="btnDownloadOrder_Click" Margin="3" VerticalAlignment="Center" Width="100" />
                <TextBlock Name="tbTotalCount" Margin="3" VerticalAlignment="Center"/>
            </StackPanel>
        </Grid>

        <TabControl Grid.Row="1" x:Name="tcOrderPages">
            <TabControl.ItemContainerStyle>
                <Style TargetType="{x:Type TabItem}">
                    <Setter Property="HeaderTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <TextBlock Text="{Binding DeliveryTemplateName}"/>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>

                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="*"/>
                                    </Grid.RowDefinitions>

                                    <Grid Grid.Row="0">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="*"/>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="*"/>
                                        </Grid.ColumnDefinitions>
                                        <CheckBox Grid.Column="0" Content="选择" Name="chkSelectAll" IsChecked="True" Checked="chkSelectAll_Checked" Unchecked="chkSelectAll_Unchecked" Margin="3" VerticalAlignment="Center" Tag="{Binding}"/>
                                        <TextBox Grid.Column="1" Text="{Binding InputCount,UpdateSourceTrigger=PropertyChanged}" Width="80" VerticalAlignment="Center" />
                                        <ProgressBar Grid.Column="2" Maximum="1" Minimum="0" Value="{Binding Progress}" Margin="3" Height="20"/>
                                        <TextBlock Grid.Column="3" Text="{Binding CurrentPrintNumber}" Margin="3" VerticalAlignment="Center" TextAlignment="Right" MinWidth="30"/>
                                        <TextBlock Grid.Column="4" Text="/" Margin="3" VerticalAlignment="Center"/>
                                        <TextBlock Grid.Column="5" Text="{Binding SelectedCount}" Margin="3" VerticalAlignment="Center" MinWidth="30" TextAlignment="Left"/>
                                        <TextBlock Grid.Column="6" Text="快递模板" VerticalAlignment="Center" Margin="3"/>
                                        <ComboBox Grid.Column="7" x:Name="cbbDeliveryTemplates" DisplayMemberPath="Name" VerticalAlignment="Center" Width="150" Margin="3" 
                                              ItemsSource="{Binding Path=DeliveryPrintTemplates,RelativeSource={RelativeSource Mode=FindAncestor,AncestorLevel=1, AncestorType=local:PrintUserControl}}" SelectionChanged="cbbDeliveryTemplates_SelectionChanged" />
                                        <TextBlock Grid.Column="8" Text="本次打印开始编号：" VerticalAlignment="Center" Margin="3"/>
                                        <TextBox Grid.Column="9" Name="tbDeliveryNumber" Text="" Margin="3" VerticalAlignment="Center" Width="150"/>
                                        <Button Grid.Column="10" Name="btnPrint" Content="{Binding PrintState}" VerticalAlignment="Center" Width="60" ClickMode="Release" Click="btnPrint_Click"  Margin="3"/>
                                    </Grid>

                                    <DataGrid ItemsSource="{Binding OrderViewModels}" Grid.Row="1" IsReadOnly="True" Margin="3" Name="dgOrders"
									          AutoGenerateColumns="False" 
									          CanUserAddRows="False"
									          CanUserDeleteRows="False"
									          CanUserResizeRows="False"
									          CanUserSortColumns="True"
                                              RowHeaderWidth="25"
									          SelectionMode="Extended"
									          SelectionUnit="CellOrRowHeader"
                                              Sorting="DataGrid_Sorting"
                                              >
                                        <DataGrid.RowHeaderStyle>
                                            <Style TargetType="DataGridRowHeader">
                                                <Setter Property="ContentTemplate">
                                                    <Setter.Value>
                                                        <DataTemplate>
                                                            <CheckBox IsChecked="{Binding Path=DataContext.IsChecked, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGridRow}},Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                                                        </DataTemplate>
                                                    </Setter.Value>
                                                </Setter>
                                            </Style>
                                        </DataGrid.RowHeaderStyle>

                                        <DataGrid.RowStyle>
                                            <Style TargetType="{x:Type DataGridRow}">
                                                <Setter Property="Background" Value="{Binding Background}"/>
                                            </Style>
                                        </DataGrid.RowStyle>
                                        
                                        <DataGrid.ContextMenu>
                                            <ContextMenu>
                                                <MenuItem Header="向前选择" Name="miSelectPre" Click="miSelectPre_Click"/>
                                                <MenuItem Header="向后选择" Name="miSelectForward" Click="miSelectForward_Click"/>
                                            </ContextMenu>
                                        </DataGrid.ContextMenu>

                                        <DataGrid.Columns>
                                            <DataGridTextColumn Header="类型" Binding="{Binding Source.CreateReason,Converter={StaticResource descriptionConverter}}"/>
                                            <DataGridTextColumn Header="编号" Binding="{Binding Source.Id}" Width="Auto"/>
                                            <DataGridTextColumn Header="卖家" Binding="{Binding Source.SellerId}" Width="Auto"/>
                                            <DataGridTextColumn Header="付款时间" Binding="{Binding Source.PayTime, StringFormat=yyyy-MM-dd HH:mm:ss}" Width="Auto"/>
                                            <DataGridTextColumn Header="商品信息" Binding="{Binding Goods}" Width="Auto" />
                                            <DataGridTextColumn Header="门牌编号" Binding="{Binding DoorNumber}" Width="Auto"/>
                                            <DataGridTextColumn Header="礼品信息" Binding="{Binding Gifts}" Width="Auto"/>
                                            <DataGridTextColumn Header="打印状态" Binding="{Binding State}" Width="Auto"/>
                                            <DataGridTextColumn Header="快递单号" Binding="{Binding DeliveryNumber}" Width="Auto"/>
                                            <DataGridTextColumn Header="收件人姓名" Binding="{Binding Source.ReceiverName}" Width="Auto"/>
                                            <DataGridTextColumn Header="收件人电话" Binding="{Binding Source.ReceiverPhone}" Width="Auto"/>
                                            <DataGridTextColumn Header="收件人手机" Binding="{Binding Source.ReceiverMobile}" Width="Auto"/>
                                            <DataGridTextColumn Header="收件人地址" Binding="{Binding Source.ReceiverAddress}" Width="Auto"/>
                                        </DataGrid.Columns>
                                    </DataGrid>
                                </Grid>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </TabControl.ItemContainerStyle>
        </TabControl>
    </Grid>
</UserControl>
